
var Grid = require('Grid')

var GridData = cc.Class({
    properties: {
        x: 0,
        y: 0,
        index: 0,
    },

    init: function(params) {
        this.index = params.index;
        this.x = params.x;
        this.y = params.y;
    },

    getKey: function() {
        return "grid" + "_" + this.x + "_" + this.y
    },
});

var BoardData = cc.Class({
    extends: cc.Component,

    properties: {
        sideNumMax: {
            default: 0,
            type: cc.Integer,
        },

        gridDataMap: null,
    },

    onLoad: function () {

    },

    init: function () {
        this.gridDataMap = {};
        this.sideNumMax = Math.max(1, this.sideNumMax);
        let radius = this.sideNumMax * 2 - 1
        for(let i = -radius + 1; i < radius; i++)
        {
            for(let j = -this.sideNumMax + 1; j < this.sideNumMax; j++)
            {
                if ( (i + j) % 2 != 0) continue;
                if ( (Math.abs(i) + Math.abs(j) > radius) ) continue;
                let index = Grid.getColorWithRandom();
                let gridData = new GridData();
                gridData.init({
                    x: i,
                    y: j,
                    index: index,
                });
                this.gridDataMap[gridData.getKey()] = gridData;
            }
        }
    },
});

module.exports = BoardData;
